# Libraries
library(rgdal)
## Loading required package: sp
## rgdal: version: 1.1-10, (SVN revision 622)
## Geospatial Data Abstraction Library extensions to R successfully loaded
## Loaded GDAL runtime: GDAL 1.11.4, released 2016/01/25
## Path to GDAL shared files: /Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgdal/gdal
## Loaded PROJ.4 runtime: Rel. 4.9.1, 04 March 2015, [PJ_VERSION: 491]
## Path to PROJ.4 shared files: /Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgdal/proj
## Linking to sp version: 1.2-3
library(leaflet)
library(RColorBrewer)
# para compilar pdf
library(webshot)
## Warning: package 'webshot' was built under R version 3.3.2
# directory
#tmp <- tempdir()
El mapa viene en un solo archivo con las tres dimensiones de detalle: paÃs>departamento>municipio
Los separé y guarde cada nivel de detalle en una carpeta separada
#library("RColorBrewer")
#library("webshot")
# Paleta de colores
#pal <- colorQuantile("YlGn", NULL, n = 5)
pal <- brewer.pal(12,"Set3")
Mapa del territorio nacional
#library("leaflet")
#library("rgdal")
#library("webshot")
# Pais
urlCol0 <-"/Users/jsalam/Documents/WorkspaceR/Visualizacion_y_Analitica/Maps/Mapas Daniela/COL_adm/0"
# Object of class SpatialPolygonsDataFrame
colombia <-readOGR(dsn = urlCol0, layer = "COL_adm0", encoding = "UTF-8")
## OGR data source with driver: ESRI Shapefile
## Source: "/Users/jsalam/Documents/WorkspaceR/Visualizacion_y_Analitica/Maps/Mapas Daniela/COL_adm/0", layer: "COL_adm0"
## with 1 features
## It has 70 fields
# Leyenda en el roll over
state_popup_Col <- paste0("<strong>Estado: </strong>", colombia$NAME_ISO)
# objeto leaflet que se pinta en el canvas
pais1 <- leaflet(data = colombia) %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(fillColor = pal, fillOpacity = 0.8, color = "#BDBDC3", weight = 1, popup = state_popup_Col)
# Pintar mapa
# Por alguna razon si pinto este mapa no se pintan los de mas abajo.
#pais1
Mapa de departamentos del territorio nacional
#library("leaflet")
#library("rgdal")
#library("webshot")
# Departamento
urlCol1 <- "/Users/jsalam/Documents/WorkspaceR/Visualizacion_y_Analitica/Maps/Mapas Daniela/COL_adm/1"
# Object of class SpatialPolygonsDataFrame
colombia1 <- readOGR(dsn = urlCol1, layer = "COL_adm1", encoding = "UTF-8")
## OGR data source with driver: ESRI Shapefile
## Source: "/Users/jsalam/Documents/WorkspaceR/Visualizacion_y_Analitica/Maps/Mapas Daniela/COL_adm/1", layer: "COL_adm1"
## with 32 features
## It has 16 fields
#summary(colombia1)
# Leyenda en el roll over
state_popup_Col <- paste0("<strong>Departamento: </strong>", colombia1$NAME_1)
#library("RColorBrewer")
# Paleta de colores
#pal <- colorQuantile("YlGn", NULL, n = 5)
pal <- brewer.pal(12,"Set3")
# objeto leaflet que se pinta en el canvas
departamentos <- leaflet(data = colombia1) %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(fillColor = pal, fillOpacity = 0.5, color = "#BDBDC3", weight = 1, popup = state_popup_Col)
# Pintar mapa
departamentos
Mapa de municipios territorio nacional
library("leaflet")
library("rgdal")
library("webshot")
# Municipio
urlCol2 <- "/Users/jsalam/Documents/WorkspaceR/Visualizacion_y_Analitica/Maps/Mapas Daniela/COL_adm/2"
# Object of class SpatialPolygonsDataFrame
colombia2 <- readOGR(dsn = urlCol2, layer = "COL_adm2", encoding = "UTF-8")
## OGR data source with driver: ESRI Shapefile
## Source: "/Users/jsalam/Documents/WorkspaceR/Visualizacion_y_Analitica/Maps/Mapas Daniela/COL_adm/2", layer: "COL_adm2"
## with 1065 features
## It has 18 fields
#summary(colombia2)
# Leyenda en el roll over
state_popup_Col <- paste0("<strong>Departamento: </strong>", colombia2$NAME_1, "<br><strong>Municipio: </strong>", colombia2$NAME_2)
# objeto leaflet que se pinta en el canvas
municipios <- leaflet(data = colombia2) %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(fillColor = pal, fillOpacity = 0.5, color = "#BDBDC3", weight = 1, popup = state_popup_Col)
# Pintar mapa
municipios